package com.winkyle.woodenfish.controller.fragment;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.winkyle.woodenfish.R;
import com.winkyle.woodenfish.controller.activity.LoginActivity;
import com.winkyle.woodenfish.controller.activity.PersonalDataActivity;
import com.winkyle.woodenfish.databinding.FragmentAccountDataBinding;
import com.winkyle.woodenfish.entity.UserInfo;
import com.winkyle.woodenfish.factory.presenterfactory.CreatePresenter;
import com.winkyle.woodenfish.mvpview.AccountDataView;
import com.winkyle.woodenfish.presenter.AccountDataPresenter;

/**
 * @author winkyle
 * @date 2018/06/15
 * @description 继承自 {@link AbstractMvpFragment}的碎片类PersonalDataFragment，app的账户资料页
 */

@CreatePresenter(value = AccountDataPresenter.class)
public class AccountDataFragment extends AbstractMvpFragment<AccountDataView,AccountDataPresenter> implements AccountDataView {

    private FragmentAccountDataBinding fragmentAccountDataBinding;

    /**
     * @description 碎片创建，指定layout布局
     * @param inflater
     * @param container
     * @param savedInstanceState 保存的碎片状态的数据
     * @return
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_account_data, container, false);
        fragmentAccountDataBinding = DataBindingUtil.bind(view);
        initFragment();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        if(isLogin()) {
            getMvpPresenter().viewPersonalData();
        }
    }

    /**
     * @description 初始化碎片的一些数据和动作
     * @return
     */
    private void initFragment() {
        fragmentAccountDataBinding.setPersonalDataView(this);
        fragmentAccountDataBinding.swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getMvpPresenter().viewPersonalData();
            }
        });
    }


    @Override
    public void toLogin(boolean toLogin) {
        if(toLogin){
            startActivity(LoginActivity.class);
            return;
        }
        startActivity(PersonalDataActivity.class);
    }

    @Override
    public void viewProceed() {
        //todo
        showRemindDialog("正在进行功能敬请期待");
    }

    @Override
    public void viewEnshrine() {
        //todo
        showRemindDialog("我的收藏功能敬请期待");
    }

    @Override
    public void viewItems() {
        //todo
        showRemindDialog("我的项目功能敬请期待");
    }

    @Override
    public void viewTeam() {
        //todo
        showRemindDialog("我的团队功能敬请期待");
    }

    @Override
    public void viewPayAccout() {
        //todo
        showRemindDialog("支付账户功能敬请期待");
    }

    @Override
    public void viewCallCenter() {
        //todo
        showRemindDialog("客服中心功能敬请期待");
    }

    @Override
    public void feedback() {
        //todo
        showRemindDialog("意见反馈功能敬请期待");
    }

    @Override
    public void set() {
        //todo
        showRemindDialog("设置功能敬请期待");
    }

    @Override
    public void refreshPersonalData(UserInfo userInfo) {
        if (fragmentAccountDataBinding.swipeRefresh.isRefreshing()){
            fragmentAccountDataBinding.swipeRefresh.setRefreshing(false);
        }
        fragmentAccountDataBinding.setUserInfo(userInfo);
    }
}
